Imports System.Data
Imports SchemaCodeGen

Partial Class pages_SchemaSnapshots_default : Inherits CPage

#region "Querystring (Filters)"
    Public ReadOnly Property Search As String
        Get
            Return CWeb.RequestStr("search")
        End Get
    End Property
    
    'Rename or Delete:
    'Public ReadOnly Property ParentId As Integer
    '    Get
    '        Return CWeb.RequestStr("parentId")
    '    End Get
    'End Property
#End Region

#Region "Members"
    Private m_schemaSnapshots As CSchemaSnapshotList
#End Region

#Region "Data"
    Public ReadOnly Property [SchemaSnapshots]() As CSchemaSnapshotList
        Get
            If IsNothing(m_schemaSnapshots) Then
                m_schemaSnapshots = New CSchemaSnapshot().SelectSearch(ctrlSchemaSnapshots.PagingInfo, txtSearch.Text) 'Sql-based Paging
                'm_schemaSnapshots.PreloadChildren() 'Loads children for page in one hit (where applicable)
            End If
            Return m_schemaSnapshots
        End Get
    End Property
    Public Function SchemaSnapshotsAsDataset() As System.Data.DataSet
        Return New CSchemaSnapshot().SelectSearch_Dataset(txtSearch.Text)
    End Function
#End Region

#Region "Event Handlers - Page "
    Protected Overrides Sub PageInit()
        'Populate Dropdowns
        
    
        'Search state (from querystring)
        txtSearch.Text = Me.Search
        
        'Display Results
        ctrlSchemaSnapshots.Display(Me.SchemaSnapshots)

        'Client-side
        Me.Form.DefaultFocus  = txtSearch.ClientID
        Me.Form.DefaultButton = btnSearch.UniqueID  'CTextbox.OnReturnPress(txtSearch, btnSearch)
    End Sub
#End Region

#Region "Event Handlers - Form"
    Protected Sub btnSearch_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnSearch.Click
        Response.Redirect(CSitemap.SchemaSnapshots(txtSearch.Text))
    End Sub
#End Region

#Region "Event Handlers - UserControl"
    Private Sub ctrl_ExportClick() Handles ctrlSchemaSnapshots.ExportClick
        CDataSrc.ExportToCsv(SchemaSnapshotsAsDataSet, Response, "SchemaSnapshots.csv")
    End Sub
    Private Sub ctrl_ResortClick(ByVal sortBy As String, ByVal descending As Boolean, ByVal pageNumber As Integer) Handles ctrlSchemaSnapshots.ResortClick
        Response.Redirect(CSitemap.SchemaSnapshots(txtSearch.Text, New CPagingInfo(0, pageNumber - 1, sortBy, descending)))
    End Sub
#End Region

End Class
